﻿using System;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Microsoft.EntityFrameworkCore.Metadata.Builders
{
    public static class PropertyBuilderExtension
    {
        /// <summary>
        /// 枚举字符串的转换
        /// </summary>
        /// <typeparam name="TEnumProperty"></typeparam>
        /// <param name="propertyBuilder"></param>
        /// <returns></returns>
        public static PropertyBuilder<TEnumProperty> HasEnumStringConversion<TEnumProperty>(
            this PropertyBuilder<TEnumProperty> propertyBuilder) where TEnumProperty : struct, Enum
        {
            return propertyBuilder.HasConversion(new YddEnumConverter<TEnumProperty>());
        }


        /// <summary>
        /// bool 类型的转换
        /// </summary>
        /// <param name="propertyBuilder"></param>
        /// <param name="falseValue"></param>
        /// <param name="trueValue"></param>
        /// <returns></returns>
        public static PropertyBuilder<bool> HasBoolToStringConversion(
            this PropertyBuilder<bool> propertyBuilder, string falseValue = "N", string trueValue = "Y")
        {
            return propertyBuilder.HasConversion(new BoolToStringConverter(falseValue, trueValue));
        }



        // /// <summary>
        // /// 
        // /// </summary>
        // /// <param name="propertyBuilder"></param>
        // /// <param name="columnType"></param>
        // /// <returns></returns>
        // public static PropertyBuilder<DateTime?> HasDateTimeStringConversion(
        //     this PropertyBuilder<DateTime?> propertyBuilder, string columnType = "char(19)")
        // {
        //
        //     return propertyBuilder.HasColumnType(columnType).HasConversion(date => FormatConvert.DatetimeToString(date),
        //         str => FormatConvert.StringToDatetime(str));
        // }
    }
}
